﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AopAlliance.Intercept;
using Models;
using IService;
using Infrastructure;

namespace Advisor
{
    public class LogAdvisor : IMethodInterceptor
    {
        public object Invoke(IMethodInvocation invocation)
        {
            object result = invocation.Proceed();
            CreateEventLog(invocation);
            return result;
        }

        private void CreateEventLog(IMethodInvocation invocation)
        {
            TaskInfo info = invocation.Arguments[0] as TaskInfo;
            EventLog log = new EventLog(info.Code, invocation.Method.Name, "xiaoboli", info.ToString());
            ILogService service = FactoryCreator.Create<ILogService>();
            service.CreateLog(log);
        }
    }
}
